/*
 * File Name: RemoveAppAction.java
 * Created on: 
 */

package co.edu.uniandes.intercon.client.action;

import java.util.Map;

import co.edu.uniandes.intercon.core.model.ApplicationDto;
import co.edu.uniandes.intercon.core.model.EMessageType;
import co.edu.uniandes.intercon.core.model.LocalApplicationList;
import co.edu.uniandes.intercon.core.model.P2PMessage;
import co.edu.uniandes.intercon.server.networking.UDPSender;

/**
 * Action used to delete the communication to the system
 * 
 * @author Fabian Gutierrez [fagossa@gmail.com]
 */
public class RemoveAppAction extends AbstractBaseGUIAction {

	/**
	 * @see AbstractBaseGUIAction#execute(Map)
	 */
	public Object execute(Map<String, Object> params) throws RuntimeException {
		int row = (Integer) params.get("row");
		ApplicationDto applicationDto = (ApplicationDto) LocalApplicationList
				.getInstance().item(row);
		if (applicationDto != null) {
			LocalApplicationList.getInstance().remove(row);
			P2PMessage message = new P2PMessage(applicationDto,
					EMessageType.DELETE);
			UDPSender.send(message);
		}
		return null;
	}

}
